﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Easy.Chat
{
    public class PMessage
    {
        public int ID { get; set; }
        public string Message { get; set; }
        public Presence From { get; set; }
        public DateTime When { get; set; }
        public int ConverID { get; set; }

        public static List<PMessage> _inMemoryMessage = new List<PMessage>();
        public static PMessage GetByID(int id)
        {
            return _inMemoryMessage.Where(m => m.ID == id).FirstOrDefault();
        }
        public static List<PMessage> GetByConversationID(int converId)
        {
            return _inMemoryMessage.Where(m => m.ConverID == converId).ToList();
        }

        public static void Add(PMessage pm)
        {
            lock (_inMemoryMessage)
            {
                pm.ID = _inMemoryMessage.Count + 1;
                _inMemoryMessage.Add(pm);

                //Conversation.GetByID(pm.ConverID).PM.Add(pm);
            }
        }
    }
}
